package io.xccit.train.member.controller;

import io.xccit.train.common.result.AjaxResult;
import io.xccit.train.member.service.MemberService;
import io.xccit.train.model.member.domain.dto.MemberDTO;
import io.xccit.train.model.member.domain.dto.MemberLoginDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author CH_ywx
 * @version 1.0
 * @create 2024/11/5
 * <p>会员控制器</p>
 */
@RestController
@RequestMapping("/member")
public class MemberController {

    @Autowired
    private MemberService memberService;

    /**
     * 查询会员总数
     * @return 总数
     */
    @GetMapping("/count")
    public AjaxResult count(){
        return AjaxResult.success(memberService.count());
    }

    /**
     * 会员注册
     * @param memberDTO 请求参数
     * @return 请求结果
     */
    @PostMapping("/register")
    public AjaxResult registry(@Validated @RequestBody MemberDTO memberDTO){
        return AjaxResult.success(memberService.registry(memberDTO));
    }

    /**
     * 发送验证码
     * @param memberDTO
     * @return 请求结果
     */
    @PostMapping("/sendCode")
    public AjaxResult sendCode(@Validated @RequestBody MemberDTO memberDTO){
        memberService.sendCode(memberDTO);
        return AjaxResult.success("短信发送成功");
    }

    /**
     * 会员登录
     * @param memberLoginDTO
     * @return
     */
    @PostMapping("/login")
    public AjaxResult login(@Validated @RequestBody MemberLoginDTO memberLoginDTO){
        return AjaxResult.success(memberService.login(memberLoginDTO));
    }
}
